
clear all

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"
local path1="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\outregs"

capture cd "`path0'Workfiles"
set more off
use completed_data, clear


	* create settler mortality with the African data corrected based on Albouy
	capture drop logmort3
	gen logmort3=logmort2
	replace logmort3=logmort if countrycode=="SGP" | countrycode=="AUS"
	
	gen lnUKdist=log(geo_UK_distw)

		
		
		
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Table 6: Horserace with economic risk
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	*** control for economic risk without intrumenting economic risk
	xi: reg pwt_ln_rgdpwok idv icrg_ERR_mean, robust
	outreg2 idv icrg_ERR_mean using "`path1'\RR_appendix_table_D5.txt" , ///
		replace bdec(3) rdec(3) aster nocons nolabel ctitle("OLS") 
		
	xi: reg pwt_ln_rgdpwok icrg_ERR_mean if idv~=., robust
	outreg2  icrg_ERR_mean using "`path1'\RR_appendix_table_D5.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS") 
		
	xi: reg pwt_ln_rgdpwok idv if icrg_ERR_mean~=., robust
	outreg2 idv  using "`path1'\RR_appendix_table_D5.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS") 
		
	xi: ivreg2 pwt_ln_rgdpwok icrg_ERR_mean (idv =distM_UK), robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv icrg_ERR_mean using "`path1'\RR_appendix_table_D5.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	xi: ivreg2 pwt_ln_rgdpwok icrg_ERR_mean (idv =distM_UK) i.continent, robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_appendix_table_D5.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV + continent") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	xi: ivreg2 pwt_ln_rgdpwok barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati icrg_ERR_mean (idv =distM_UK), robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_appendix_table_D5.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV + muslim") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	xi: ivreg2 pwt_ln_rgdpwok barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati icrg_ERR_mean i.continent (idv =distM_UK), robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_appendix_table_D5.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV + all") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*** instrument economic risk with settle mortality	

	xi: reg pwt_ln_rgdpwok idv if icrg_ERR_mean~=. & logmort~=.& idv~=., robust
	outreg2 idv  using "`path1'\RR_table005B.txt" , ///
		replace bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: idv only") 
	
	xi: reg pwt_ln_rgdpwok icrg_ERR_mean if  icrg_ERR_mean~=. &logmort~=. & idv~=., robust
	outreg2  icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: icrg only") 
		
	xi: reg pwt_ln_rgdpwok idv icrg_ERR_mean if  icrg_ERR_mean~=. &logmort~=.& idv~=., robust
	outreg2 idv icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: mortality") 
		
		
	xi: ivreg2 pwt_ln_rgdpwok  (idv =distM_UK) if  icrg_ERR_mean~=. & logmort~=.& idv~=., robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: blood + mortality") ///
		addstat("1st stage F-stat (idv)", `Ffirst',"Partial R2 (idv)",`R2first')
		
	xi: ivreg2 pwt_ln_rgdpwok  (icrg_ERR_mean=logmort) if  icrg_ERR_mean~=. & logmort~=.& idv~=., robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: blood + mortality") ///
		addstat("1st stage F-stat (risk)", `Ffirst',"Partial R2 (risk)",`R2first')
		

	xi: ivreg2 pwt_ln_rgdpwok  (idv icrg_ERR_mean=logmort distM_UK), robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	local R2first2=A[2,2]
	local Ffirst2 =A[3,2]	
	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: blood + mortality") ///
		addstat("1st stage F-stat (idv)", `Ffirst',"Partial R2 (idv)",`R2first',"1st stage F-stat (risk)", `Ffirst2',"Partial R2 (risk)",`R2first2')
		
	xi: ivreg2 pwt_ln_rgdpwok  (icrg_ERR_mean=logmort3) if  icrg_ERR_mean~=. & logmort~=.& idv~=., robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV Albouy: blood + mortality") ///
		addstat("1st stage F-stat (risk)", `Ffirst',"Partial R2 (risk)",`R2first')
		
	xi: ivreg2 pwt_ln_rgdpwok  (idv icrg_ERR_mean=logmort3 distM_UK) if   icrg_ERR_mean~=. & logmort~=.& idv~=., robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]	
	local R2first2=A[2,2]
	local Ffirst2 =A[3,2]	
	
	outreg2 idv icrg_ERR_mean using "`path1'\RR_table005B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV Albouy: blood + mortality") ///
		addstat("1st stage F-stat (idv)", `Ffirst',"Partial R2 (idv)",`R2first',"1st stage F-stat (risk)", `Ffirst2',"Partial R2 (risk)",`R2first2')
		
	

	
